package com.atzon.service.impl;

import com.atzon.DAO.ArtDAO;
import com.atzon.model.Article;
import com.atzon.service.ArtService;

import java.util.List;
import java.util.Map;

public class ArtServiceImpl implements ArtService {
    private ArtDAO artDAO = new ArtDAO();
    @Override
    public void addCount(Integer aId) {
        Article art = artDAO.getArtById(aId);
        if (null != art) {
            Integer count = 0;
            if (null != art.getBrowseCount()) {
                count = art.getBrowseCount();
                System.out.println(count);
            }
            artDAO.updateArt(aId,count + 1);
        }
    }
    @Override
    public void delFavById(Integer uId, Integer aId) {
        artDAO.delFavById(uId, aId);
    }
    @Override
    public void addArt(String title, String content, String username, Integer userId) {
        artDAO.addArt(title,content,username,userId);
    }
    @Override
    public long findTotalArtCount(Integer userId) {
        return artDAO.getTotalArt(userId);
    }
    @Override
    public long findTotalFavCount(Integer userId) {
        return artDAO.getTotalFav(userId);
    }
    @Override
    public Map<String, Object> findArtById(Integer artId) {
        return artDAO.findArtById(artId);
    }
    @Override
    public List<Map<String, Object>> findArtList(Integer userId, int page, String search) {
        return artDAO.findArt(userId, page, search);
    }
    @Override
    public List<Map<String, Object>> findFavList(Integer userId, int page, String search) {
        return artDAO.findFav(userId, page, search);
    }
    @Override
    public List<Map<String, Object>> findFavUser(Integer artId) {
        return artDAO.findFavUser(artId);
    }
}
